<?php
/**
 * @copyright 2011
 * @version $Id$
 * @access public
 * @author Oriotiori

 */

Class Default_Model_Userinfo  extends Zend_Db_Table_Abstract{

	protected $_name = 'users';



	/*************************/
	function getPersonalInfo($to)
	{
		$TO = new Default_Model_TO_Userinfo();
		$x_id = $to['User_Id'];
			
		try{
			$sql= $this->getAdapter()->select()
			->from(array('u'=> TABLE_PREFIX.$this->_name))
			->joinLeft(array('ui'=> TABLE_PREFIX.'user_information'), 'ui.User_Id=u.Id', array('ui.Picture_Id'))
			->where('u.Id=?', $x_id);

			$data = $this->getAdapter()->fetchAll($sql);
			$rowCount = count($data);

			if ($rowCount > 0){

				foreach($data as $dt){

					$TO->setUser_Id($dt['Id']);
					$TO->setUsername($dt['Username']);
					$TO->setEmail($dt['Email']);
					$TO->setRole($dt['Role']);
					$TO->setStatus($dt['Status']);
					$TO->setPicture_Id($dt['Picture_Id']);
					$TO->add();
				}

				$data = $TO->getAllData();
				return $data;
			}
			else
			{
				throw new Exception('No found results.');
			}

		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}

	}




	/**
	 * Model_userAccess::isAllow()
	 *
	 * @param mixed $userAccess
	 * @return
	 */
	function isAllow($userAccess)
	{
		$User_Id = $userAccess['User_Id'];
		$Module_Id = $userAccess['Module_Id'];

		try{
			if($User_Id =='' || $Module_Id == '')
			return false;

			if($Module_Id == 0)
			return true;

			$sql=$this
				->getAdapter()
				->select()
				->from(TABLE_PREFIX.'useraccess', '*')
				->where('User_Id=?', $User_Id)->where('Module_Id=?', $Module_Id);

			$data = $this->getAdapter()->fetchAll($sql);

			$rowCount = count($data);

			if ($rowCount > 0)
			return true;
			else
			return false;

		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}


		
}


?>